add private_optional support (and wire up tests/CI)#3278
Merged
Jens-G merged 1 commit intoapache:masterfrom Jan 22, 2026
Merged
add private_optional support (and wire up tests/CI)#3278Jens-G merged 1 commit intoapache:masterfrom
private_optional support (and wire up tests/CI)#3278Jens-G merged 1 commit intoapache:masterfrom
Conversation
private_optional support (and wire up tests/CI)private_optional support (and wire up tests/CI)
Jens-G
requested changes
Jan 7, 2026
| @@ -0,0 +1,132 @@ | |||
| // Minimal parser support for compiler unit tests. | |||
Member
There was a problem hiding this comment.
there is a number of new files lacking the ASF license header
Contributor
Author
There was a problem hiding this comment.
thanks, added the ASF license header.
cf288f6 to
922f4c4
Compare
Jens-G
requested changes
Jan 11, 2026
Member
Jens-G
left a comment
There was a problem hiding this comment.
I would love to also see a second opinion from the c++ Thrift committers.
Add a new `cpp:private_optional` generator option for C++ that emits optional fields as private members and provides const getters, enabling stricter encapsulation while preserving access for generated helpers.
To keep the feature stable and exercised in automation, add fixture-based compiler tests and the minimal build/CI wiring required for those tests to build and run in the workflow (including MSVC).
### Example generated code (behavior change only, from `TestStruct`)
#### Default (no `cpp:private_optional`): optional fields stay public
```cpp
public:
int32_t required_field;
int32_t optional_field;
std::string optional_string;
```
With cpp:private_optional: optional fields become private + const getters
```cpp
public:
int32_t required_field;
const int32_t& __get_optional_field() const { return optional_field; }
const std::string& __get_optional_string() const { return optional_string; }
private:
int32_t optional_field;
std::string optional_string;
friend void swap(TestStruct &a, TestStruct &b) noexcept;
friend std::ostream& operator<<(std::ostream& out, const TestStruct& obj);
```
922f4c4 to
091a00b
Compare
Contributor
Author
Hi Jens, wondering if you have a specific set of folks in mind that needed to be mentioned in the PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a new
cpp:private_optionalgenerator option for C++ that emits optional fields as private members and provides const getters, enabling stricter encapsulation while preserving access for generated helpers.To keep the feature stable and exercised in automation, add fixture-based compiler tests and the minimal build/CI wiring required for those tests to build and run in the workflow (including MSVC).
Example generated code (behavior change only, from
TestStruct)Default (no
cpp:private_optional): optional fields stay publicWith cpp:private_optional: optional fields become private + const getters
[skip ci]anywhere in the commit message to free up build resources.